package com.pan.server.mapper;

import com.pan.pojo.dto.UserDTO;
import com.pan.pojo.entity.User;
import com.pan.pojo.vo.UserAdminVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {

    /**
     * 根据用户名查询用户信息
     * @param username
     * @return
     */
    @Select("select * from user where username = #{username}")
    User selectByUsername(String username);

    /**
     * 新增用户
     * @param user
     * @return
     */
    @Insert("insert into user(username, password, name, gender, permission_id, location) value(#{username}, #{password}, #{name}, #{gender}, #{permissionId}, #{location})")
    void insert(User user);

    /**
     * 更新用户信息
     * @param userDTO
     */
    @Update("update user set name = #{name}, gender = #{gender}, location = #{location}, password = #{password} where username = #{username}")
    void updateUser(UserDTO userDTO);

    /**
     * 根据用户名查询用户ID
     * @param username
     * @return
     */
    @Select("select user_id from user where username = #{username}")
    Long selectUserIDByUsername(String username);

    /**
     * 查询所有用户
     * @return
     */
    @Select("select user_id, username, name, gender, permission_id, location from user")
    List<UserAdminVO> getAllUsers();

    /**
     * 删除用户
     * @param id
     */
    @Delete("delete from user where user_id = #{id}")
    void deleteUser(Integer id);

    /**
     * 更新用户权限
     * @param map
     */
    void updateUserAdmin(Map<String, Object> map);
}